{extend name="index/public" /}

{block name="content"}
<form class="layui-form" action="" id="searchBox">
    <div class="layui-inline">
        <div class="layui-input-inline">
            {MyTag:channel type='manage' /}
        </div>
    </div>
    <div class="layui-inline" style="width: 800px;">
        <button class="layui-btn toolBtn my-btn my-btn-sm" type="button" id="custom">自定义游戏比例</button>
    </div>
</form>

<table id="tableBox" lay-filter="tableBox"></table>
{/block}

{block name="css"}
{/block}

{block name="js"}
<script>
    layui.use('table', function(){
        var table = layui.table
            ,$ = layui.$
            ,form = layui.form
            ,load = null
            ,active = {
                reload: function () {
                    var channel_id = $('#channel_id').val();

                    table.reload('tableId', {
                        page: {curr: 1}
                        , where: {channel_id:channel_id}
                        ,height: 'full-100'
                    })
                },
            };

        //表格初始化
        table.render({
            elem: '#tableBox'
            ,height: 'full-100'
            ,url: '{:url("AuditSdkInfo/index")}'
            ,page: true
            ,limit:20
            ,limits:[20,40,60,80]
            ,loading:true
            ,id:'tableId'
            ,done: function (res, curr, count) {
                layer.close(load);
                $('#layui-loading').hide();

                if(layui.data('auditCpInfoPrompt').onOff==undefined){
                    var statusObj = $('.layui-table-main>table>tbody tr:eq(0) td:eq(2)');
                    layer.tips('可即时编辑', statusObj, {tips: 3, tipsMore:true, time: 5000});
                    layui.data('auditCpInfoPrompt', {key: 'onOff',value: 1});
                }
            }
            ,cols: [[
                {field:'channel_id', title: '渠道ID', width: 80, sort:true}
                ,{field:'channel_name', title: '渠道名称' , width: 100}
                ,{field:'channel_rate', title: '渠道费率' , width: 90, edit: 'text'}
                ,{field:'tax_rate', title: '税率' , width: 80, edit: 'text'}
                ,{field:'pay_rate', title: '分成比例', width: 90, edit: 'text'}
                ,{field:'company', title: '公司名称' , width: 150, edit: 'text'}
                ,{field:'reg_address', title: '注册地址' , width: 150, edit: 'text'}
                ,{field:'contact_phone', title: '注册电话' , width: 100, edit: 'text'}
                ,{field:'contact_mobile', title: '联系电话' , width: 100, edit: 'text'}
                ,{field:'contact_man', title: '联系人' , width: 70, edit: 'text'}
                ,{field:'open_name', title: '开户名称' , width: 120, edit: 'text'}
                ,{field:'open_bank', title: '开户银行' , width: 100, edit: 'text'}
                ,{field:'open_account', title: '开户账号' , width: 100, edit: 'text'}
                ,{field:'credit_code', title: '信用代码' , width: 100, edit: 'text'}
                ,{field:'send_address', title: '邮寄地址' , width: 100, edit: 'text'}
                ,{field:'audit_time', title: '最后回款时间' , width: 120}
            ]]
        });
//
        //监听搜索下拉菜单
        form.on('select(channel_id)', function(data){
            load = layer.load();
            active['reload'].call(this)
        });

        //监听单元格编辑
        table.on('edit(tableBox)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field
                ,params = {}
                ,load = layer.load();

            if(field=='channel_rate'){
                params = {channel_id:data.channel_id, channel_rate:value};
            }else if(field=='pay_rate'){
                params = {channel_id:data.channel_id, pay_rate:value};
            }else if(field=='tax_rate'){
                params = {channel_id:data.channel_id, tax_rate:value};
            }else if(field=='company'){
                params = {channel_id:data.channel_id, company:value};
            }else if(field=='reg_address'){
                params = {channel_id:data.channel_id, reg_address:value};
            }else if(field=='contact_phone'){
                params = {channel_id:data.channel_id, contact_phone:value};
            }else if(field=='contact_man'){
                params = {channel_id:data.channel_id, contact_man:value};
            }else if(field=='open_name'){
                params = {channel_id:data.channel_id, open_name:value};
            }else if(field=='open_bank'){
                params = {channel_id:data.channel_id, open_bank:value};
            }else if(field=='open_account'){
                params = {channel_id:data.channel_id, open_account:value};
            }else if(field=='credit_code'){
                params = {channel_id:data.channel_id, credit_code:value};
            }else if(field=='send_address'){
                params = {channel_id:data.channel_id, send_address:value};
            }else if(field=='contact_mobile'){
                params = {channel_id:data.channel_id, contact_mobile:value};
            }

            $.post('{:url("AuditSdkInfo/edit")}',params, function(json){
                layer.close(load);
                if(json.code==0){
                    layer.msg(json.msg, {icon: 1, time:1000})
                }else{
                    layer.msg(json.msg, {icon: 0, time:1000});
                }
            }, 'JSON').error(function(){
                layer.close(load);
                layer.msg('连接超时，请联系后台管理员', {icon: 2, time:3000});
            });
        });

        $('#searchBox .toolBtn').on('click', function(){
            if($(this).attr('id')=='custom'){
                layer.open({
                    type: 2
                    ,title: '自定义游戏比例'
                    ,area: ['1200px', '700px']
                    ,offset: '100px'
                    ,resize: true
                    ,content: '{:url("AuditSdkInfo/custom")}'
                });
            }
        });

    });
</script>
{/block}